package com.free.semantic.infrastruct.mapper;

import com.free.semantic.infrastruct.common.ModelMarketRelDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 模型与市场关联Mapper接口
 */
@Mapper
public interface ModelMarketRelMapper {
    
    @Select("SELECT * FROM model_market_rel WHERE id = #{id}")
    ModelMarketRelDO findById(@Param("id") Long id);
    
    @Select("SELECT * FROM model_market_rel WHERE model_id = #{modelId}")
    List<ModelMarketRelDO> findByModelId(@Param("modelId") Long modelId);
    
    @Select("SELECT * FROM model_market_rel WHERE market_id = #{marketId}")
    List<ModelMarketRelDO> findByMarketId(@Param("marketId") Long marketId);
    
    @Insert("INSERT INTO model_market_rel(model_id, market_id, create_time) " +
            "VALUES(#{modelId}, #{marketId}, NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(ModelMarketRelDO modelMarketRelDO);
    
    @Delete("DELETE FROM model_market_rel WHERE id = #{id}")
    int deleteById(@Param("id") Long id);
    
    @Delete("DELETE FROM model_market_rel WHERE model_id = #{modelId} AND market_id = #{marketId}")
    int deleteByModelIdAndMarketId(@Param("modelId") Long modelId, @Param("marketId") Long marketId);
    
    @Delete("DELETE FROM model_market_rel WHERE model_id = #{modelId}")
    int deleteByModelId(@Param("modelId") Long modelId);
    
    @Delete("DELETE FROM model_market_rel WHERE market_id = #{marketId}")
    int deleteByMarketId(@Param("marketId") Long marketId);
} 